home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000499 / patchSG0000499.idb / usr / include / abi / X11 / extensions / extutil.h.z / extutil.h
Encoding:
C/C++ Source or Header  |  1995-06-12  |  4.3 KB  |  117 lines

  1. /*
  2.  * $XConsortium: extutil.h,v 1.11 89/12/09 21:12:33 rws Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Jim Fulton, MIT X Consortium
  24.  * 
  25.  *                     Xlib Extension-Writing Utilities
  26.  *
  27.  * This package contains utilities for writing the client API for various
  28.  * protocol extensions.  THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
  29.  * ARE SUBJECT TO CHANGE!
  30.  */
  31.  
  32. #ifndef _EXTUTIL_H_
  33. #define _EXTUTIL_H_
  34.  
  35. /*
  36.  * We need to keep a list of open displays since the Xlib display list isn't
  37.  * public.  We also have to per-display info in a separate block since it isn't
  38.  * stored directly in the Display structure.
  39.  */
  40. typedef struct _XExtDisplayInfo {
  41.     struct _XExtDisplayInfo *next;    /* keep a linked list */
  42.     Display *display;            /* which display this is */
  43.     XExtCodes *codes;            /* the extension protocol codes */
  44.     caddr_t data;            /* extra data for extension to use */
  45. } XExtDisplayInfo;
  46.  
  47. typedef struct _XExtensionInfo {
  48.     XExtDisplayInfo *head;        /* start of list */
  49.     XExtDisplayInfo *cur;        /* most recently used */
  50.     int ndisplays;            /* number of displays */
  51. } XExtensionInfo;
  52.  
  53. typedef struct _XExtensionHooks {
  54.     int (*create_gc)();
  55.     int (*copy_gc)();
  56.     int (*flush_gc)();
  57.     int (*free_gc)();
  58.     int (*create_font)();
  59.     int (*free_font)();
  60.     int (*close_display)();
  61.     Bool (*wire_to_event)();
  62.     Status (*event_to_wire)();
  63.     int (*error)();
  64.     char *(*error_string)();
  65. } XExtensionHooks;
  66.  
  67. extern XExtensionInfo *XextCreateExtension(void);
  68. extern void XextDestroyExtension(XExtensionInfo *info);
  69. extern XExtDisplayInfo *XextAddDisplay(XExtensionInfo *, Display *, char *, 
  70.                     XExtensionHooks *, int, caddr_t);
  71. extern int XextRemoveDisplay(XExtensionInfo *, Display *);
  72. extern XExtDisplayInfo *XextFindDisplay(XExtensionInfo *, Display *);
  73.  
  74. #define XextHasExtension(i) ((i) && ((i)->codes))
  75. #define XextCheckExtension(dpy,i,name,val) \
  76.   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
  77. #define XextSimpleCheckExtension(dpy,i,name) \
  78.   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
  79.  
  80.  
  81. /*
  82.  * helper macros to generate code that is common to all extensions; caller
  83.  * should prefix it with static if extension source is in one file; this
  84.  * could be a utility function, but have to stack 6 unused arguments for 
  85.  * something that is called many, many times would be bad.
  86.  */
  87. #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
  88. XExtDisplayInfo *proc (Display *dpy) \
  89. { \
  90.     XExtDisplayInfo *dpyinfo; \
  91.     if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
  92.     if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
  93.       dpyinfo = XextAddDisplay (extinfo,dpy,(char *)extname,hooks,nev,data); \
  94.     return dpyinfo; \
  95. }
  96.  
  97. #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
  98. int proc (Display *dpy, XExtCodes *codes) \
  99. { \
  100.     return XextRemoveDisplay (extinfo, dpy); \
  101. }
  102.  
  103. #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
  104. char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
  105. {  \
  106.     code -= codes->first_error;  \
  107.     if (code >= 0 && code < nerr) { \
  108.     char tmp[256]; \
  109.     sprintf (tmp, "%s.%d", extname, code); \
  110.     XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
  111.     return buf; \
  112.     } \
  113.     return (char *)0; \
  114. }
  115.  
  116. #endif
  117.